package com.cleaningcloud.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.erp.domain.dto.ErpSaleReturnDto;
import com.cleaningcloud.erp.domain.vo.ErpSaleReturnVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.domain.ErpSaleReturn;
import com.cleaningcloud.erp.service.IErpSaleReturnService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 销售退换货Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-03
 */
@RestController
@RequestMapping("/ErpSaleReturn")
public class ErpSaleReturnController extends BaseController
{
    @Autowired
    private IErpSaleReturnService erpSaleReturnService;

    /**
     * 查询销售退换货列表
     */
    @RequiresPermissions("erp:ErpSaleReturn:list")
    @GetMapping("/list")
    public TableDataInfo list(ErpSaleReturn erpSaleReturn)
    {
        startPage();
        List<ErpSaleReturnVo> list = erpSaleReturnService.selectErpSaleReturnList(erpSaleReturn);
        return getDataTable(list);
    }

    /**
     * 导出销售退换货列表
     */
    @RequiresPermissions("erp:ErpSaleReturn:export")
    @Log(title = "销售退换货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpSaleReturn erpSaleReturn)
    {
        List<ErpSaleReturnVo> list = erpSaleReturnService.selectErpSaleReturnList(erpSaleReturn);
        ExcelUtil<ErpSaleReturnVo> util = new ExcelUtil<ErpSaleReturnVo>(ErpSaleReturnVo.class);
        util.exportExcel(response, list, "销售退换货数据");
    }

    /**
     * 获取销售退换货详细信息
     */
    @RequiresPermissions("erp:ErpSaleReturn:query")
    @GetMapping(value = "/{saleReturnId}")
    public AjaxResult getInfo(@PathVariable("saleReturnId") Long saleReturnId)
    {
        return success(erpSaleReturnService.selectErpSaleReturnBySaleReturnId(saleReturnId));
    }

    /**
     * 新增销售退换货
     */
    @RequiresPermissions("erp:ErpSaleReturn:add")
    @Log(title = "销售退换货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpSaleReturnDto erpSaleReturn)
    {
        return toAjax(erpSaleReturnService.insertErpSaleReturn(erpSaleReturn));
    }

    /**
     * 修改销售退换货
     */
    @RequiresPermissions("erp:ErpSaleReturn:edit")
    @Log(title = "销售退换货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpSaleReturnDto erpSaleReturn)
    {
        return toAjax(erpSaleReturnService.updateErpSaleReturn(erpSaleReturn));
    }


    /**
     * 审核售退换货
     */
    @RequiresPermissions("erp:ErpSaleReturn:audit")
    @Log(title = "销售退换货审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody ErpSaleReturn erpSaleReturn)
    {
        return toAjax(erpSaleReturnService.auditErpSaleReturn(erpSaleReturn));
    }

    /**
     * 删除销售退换货
     */
    @RequiresPermissions("erp:ErpSaleReturn:remove")
    @Log(title = "销售退换货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{saleReturnIds}")
    public AjaxResult remove(@PathVariable Long[] saleReturnIds)
    {
        return toAjax(erpSaleReturnService.deleteErpSaleReturnBySaleReturnIds(saleReturnIds));
    }
}
